/*
 * Copyright 2012 Banaanvraag.
 *
 * MIT License, details are found in the LICENSE text file
 */

package banaanvraag.tools.conversion;

import java.util.List;

/** Tools for converting arrays and lists
 *
 * @author Wukl
 */
public class ArrayConversion {
    
    /** Convert a Byte array (object) to a byte array (primitive)
     * 
     * @param array The Byte array
     * @return The byte array containing the values of the Byte array
     */
    public static byte[] ByteToByte(Byte[] array) {
        byte[] ret = new byte[array.length];
        int i = 0;
        while(i < array.length) {
            ret[i] = array[i];
            i++;
        }
        return ret;
    }
    
    /** Convert a byte array (primitive) to a Byte array (object)
     * 
     * @param array The byte array
     * @return The Byte array containing the values of the byte array
     */
    public static Byte[] byteToByte(byte[] array) {
        Byte[] ret = new Byte[array.length];
        int i = 0;
        while(i < array.length) {
            ret[i] = array[i];
            i++;
        }
        return ret;
    }
    
    /**
     * Take a Byte list and return a byte array.
     * @param list The Byte list.
     * @return The byte array.
     * @deprecated Use ByteArrayList instead.
     */
    public static byte[] listToArray(List<Byte> list) {
        byte[] ret = new byte[list.size()];
        int i = 0;
        while(i < list.size()) {
            ret[i] = list.get(i);
            i++;
        }
        return ret;
    }
    
    /**
     * Take a String list and return a String array
     * @param list The String list
     * @return The byte array
     */
    public static String[] stringListToArray(List<String> list) {
        String[] ret = new String[list.size()];
        int i = 0;
        while(i < list.size()) {
            ret[i] = list.get(i);
            i++;
        }
        return ret;
    }
    
    /**
     * Take an Integer List and return an int array
     * @param list The Integer list
     * @return The int array
     */
    public static int[] intListToArray(List<Integer> list) {
        int[] ret = new int[list.size()];
        int i = 0;
        while(i < list.size()) {
            ret[i] = list.get(i);
            i++;
        }
        return ret;
    }
    
    /**
     * Take a Short list and return a short array
     * @param list The Short list
     * @return The short array
     */
    public static short[] shortListToArray(List<Short> list) {
        short[] ret = new short[list.size()];
        int i = 0;
        while(i < list.size()) {
            ret[i] = list.get(i);
            i++;
        }
        return ret;
    }
}
